package com.jf3q.sup.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.sup.domain.Purchases;
import com.jf3q.sup.dto.PurchasesAddDto;
import com.jf3q.sup.dto.PurchasesPageDto;
import com.jf3q.sup.service.PurchasesService;
import com.jf3q.sup.mapper.PurchasesMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 *
 */
@Service
public class PurchasesServiceImpl extends ServiceImpl<PurchasesMapper, Purchases>
    implements PurchasesService{

    @Autowired
    PurchasesMapper purchasesMapper;

    @Override
    public Page findPageList(PurchasesPageDto pageDto) {
        Page<Purchases> page = new Page<>(pageDto.getPageNow(),5);
        Page pages = purchasesMapper.getPage(page, pageDto.getSupplierId(), pageDto.getPurchaseDate());
        return pages;
    }

    @Override
    public Integer addPurchases(PurchasesAddDto addDto) {
        Purchases purchases = new Purchases();
        purchases.setCreatedAt(new Date(System.currentTimeMillis()));
        purchases.setUpdatedAt(new Date(System.currentTimeMillis()));
        BeanUtils.copyProperties(addDto,purchases);
        purchasesMapper.insert(purchases);
        return purchases.getId();
    }
}




